import React, { createContext, useContext, useState } from "react";
import config from '../config/config';

const GlobalStateContext = createContext();

export function GlobalStateProvider({children}) {

    const [themeColor, setThemeColor] = useState(config.theme_color[0].value);
    const [currentUser, setCurrentUser] = useState({});
    const [eventSource, setEventSource] = useState(new EventSource(config.TAIXU_SYSTEM_API + "/common/message"));

    const value = { themeColor, setThemeColor, currentUser, setCurrentUser, eventSource, setEventSource };

    return (
        <GlobalStateContext.Provider value={value}>
            {children}
        </GlobalStateContext.Provider>
    );
}

export const useGlobalShare = () => useContext(GlobalStateContext);
